package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.vo.request.NewFileSearchVo;
import com.zhijian.medical.entity.vo.response.CnasFileAllVo;
import com.zhijian.medical.entity.vo.response.CnasSortNameVo;
import com.zhijian.medical.entity.vo.response.NewFileVo;
import com.zhijian.medical.enums.NewFileTypeEnum;
import com.zhijian.medical.service.CnasFileService;
import com.zhijian.medical.service.CnasSortNameService;
import com.zhijian.medical.service.NewFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

/**
 * CNAS认可
 *
 * @author HCG
 * @version 1.0
 * @date 2023-03-07 16:37:16
 */
@Slf4j
@Controller
@Api(tags = "CNAS认可")
public class CnasSortNameController {

    @Autowired
    private CnasSortNameService service;

    @Autowired
    private NewFileService newFileService;

    @Autowired
    private CnasFileService cnasFileService;

    /**
     * 查询某个要素下的底层树状数据
     *
     * @param ysSort
     * @return
     */
    @Response
    @GetMapping("/cnas/sort/name/tree")
    @ApiOperation("查询某个要素下的底层树状数据")
    public List<CnasSortNameVo> delete(@ApiParam(name = "ysSort", value = "要素序号")
                                       @RequestParam(value = "ysSort") String ysSort) {
        return service.renderTreeList(ysSort);
    }

    /**
     * 获取供选择的记录表单所有文件
     *
     * @return
     */
    @Response
    @GetMapping("/cnas/file/list/jlbd")
    @ApiOperation("获取供选择的记录表单所有文件")
    public List<NewFileVo> getZngsFileList() {
        return newFileService.selectList(NewFileSearchVo.builder()
                .type(NewFileTypeEnum.JLBD.getCode())
                .build());
    }

    /**
     * 获取供选择的质量手册与程序文件所有文件
     *
     * @return
     */
    @Response
    @GetMapping("/cnas/file/list/zlsc/cxwj")
    @ApiOperation("获取供选择的质量手册与程序文件所有文件")
    public List<NewFileVo> getZlscAndCxwjFileList() {
        return newFileService.selectList(NewFileSearchVo.builder()
                .typeList(Arrays.asList(NewFileTypeEnum.ZLSC.getCode(), NewFileTypeEnum.CXWJ.getCode()))
                .build());
    }

    /**
     * 获取供选择的相关性政策所有文件
     *
     * @return
     */
    @Response
    @GetMapping("/cnas/file/list/xgx")
    @ApiOperation("获取供选择的相关性政策所有文件")
    public List<NewFileVo> getXgxFileList() {
        return newFileService.selectList(NewFileSearchVo.builder()
                .typeList(Arrays.asList(NewFileTypeEnum.FLBZ.getCode(), NewFileTypeEnum.ZNGS.getCode()))
                .build());
    }

    /**
     * 添加科室自己编写的相应管理要素的文件
     *
     * @param sortNameId
     * @param fileId
     * @return
     */
    @Response
    @PostMapping("/cnas/file/ks")
    @ApiOperation("添加科室自己编写的相应管理要素的文件")
    public boolean addKsSlefFile(@ApiParam(name = "sortNameId", value = "序号id") @RequestParam(value = "sortNameId") Long sortNameId,
                                 @ApiParam(name = "fileId", value = "文件id") @RequestParam(value = "fileId") Long fileId) {
        return cnasFileService.addKsSlefFile(sortNameId, fileId);
    }

    /**
     * 添加文件具体内容中相关政策性文件
     *
     * @param sortNameId
     * @param fileId
     * @return
     */
    @Response
    @PostMapping("/cnas/file/xgzc")
    @ApiOperation("添加文件具体内容中相关政策性文件")
    public boolean addXgzcsFile(@ApiParam(name = "sortNameId", value = "序号id") @RequestParam(value = "sortNameId") Long sortNameId,
                                @ApiParam(name = "fileId", value = "文件id") @RequestParam(value = "fileId") Long fileId) {
        return cnasFileService.addXgzcsFile(sortNameId, fileId);
    }

    /**
     * 添加表格文件
     *
     * @param sortNameId
     * @param fileId
     * @param parentKsId
     * @return
     */
    @Response
    @PostMapping("/cnas/file/bg")
    @ApiOperation("添加表格文件")
    public boolean addBgFile(@ApiParam(name = "sortNameId", value = "序号id") @RequestParam(value = "sortNameId") Long sortNameId,
                             @ApiParam(name = "fileId", value = "文件id") @RequestParam(value = "fileId") Long fileId,
                             @ApiParam(name = "parentKsId", value = "父文件记录id") @RequestParam(value = "parentKsId") Long parentKsId) {
        return cnasFileService.addBgFile(sortNameId, fileId, parentKsId);
    }

    /**
     * 查出一个序号，所有包含的文件
     *
     * @param cnasNameId
     * @return
     */
    @Response
    @GetMapping("/cnas/file/{cnasNameId}")
    @ApiOperation("查出一个序号，所有包含的文件")
    public CnasFileAllVo selectCnasFileAllVo(@ApiParam(name = "cnasNameId", value = "序号id")
                                             @PathVariable("cnasNameId") Long cnasNameId) {
        return cnasFileService.selectCnasFileAllVo(cnasNameId);
    }

}